package ${package.Controller};

import com.gilight.base.base.ResultEntity;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;

<#if restControllerStyle>

<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${table.serviceImplName?uncap_first};


    @ApiOperation(value = "根据id查询")
    @RequestMapping(value = "/selectById", method = {RequestMethod.GET})
    public ResultEntity selectById(${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setData(${table.serviceImplName?uncap_first}.getById(${entity?uncap_first}.getId()));
        return resultEntity;
    }

    @ApiOperation(value = "条件查询")
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    public ResultEntity list(${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        resultEntity.setData(${table.serviceImplName?uncap_first}.list(queryWrapper));
        return resultEntity;
    }

    @ApiOperation(value = "分页条件查询")
    @RequestMapping(value = "/page", method = {RequestMethod.GET})
    public ResultEntity page(${entity} ${entity?uncap_first},
                            @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {
        ResultEntity resultEntity = new ResultEntity();
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        Page page = new Page(pageNo,pageSize);
        resultEntity.setData(${table.serviceImplName?uncap_first}.page(page,queryWrapper));
        return resultEntity;
    }

    @ApiOperation(value = "添加")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public ResultEntity save(@RequestBody ${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        ${table.serviceImplName?uncap_first}.save(${entity?uncap_first});
        return resultEntity;
    }

    @ApiOperation(value = "批量添加")
    @RequestMapping(value = "/saveBatch", method = {RequestMethod.POST})
    public ResultEntity save(@RequestBody List<${entity}> list) {
        ResultEntity resultEntity = new ResultEntity();
        ${table.serviceImplName?uncap_first}.saveBatch(list);
        return resultEntity;
    }

    @ApiOperation(value = "更新")
    @RequestMapping(value = "/updateById", method = {RequestMethod.POST})
    public ResultEntity updateById(@RequestBody ${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        ${table.serviceImplName?uncap_first}.updateById(${entity?uncap_first});
        return resultEntity;
    }

    @ApiOperation(value = "添加或更新")
    @RequestMapping(value = "/saveOrUpdate", method = {RequestMethod.POST})
    public ResultEntity saveOrUpdate(@RequestBody ${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        ${table.serviceImplName?uncap_first}.saveOrUpdate(${entity?uncap_first});
        return resultEntity;
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/removeById", method = {RequestMethod.POST})
    public ResultEntity removeById(@RequestBody ${entity} ${entity?uncap_first}) {
        ResultEntity resultEntity = new ResultEntity();
        ${table.serviceImplName?uncap_first}.removeById(${entity?uncap_first}.getId());
        return resultEntity;
    }

}
</#if>
